package com.huabo.system.service.impl;

import com.hbfk.util.PageInfo;
import com.huabo.system.config.DateBaseConfig;
import com.huabo.system.mysql.entity.TblIndicatorMySql;
import com.huabo.system.mysql.mapper.TblIndicatorMySqlMapper;
import com.huabo.system.oracle.entity.TblIndicator;
import com.huabo.system.oracle.mapper.TblIndicatorMapper;
import com.huabo.system.service.TblIndicatorService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@Service
public class TblIndicatorServiceImpl implements TblIndicatorService {

    @Resource
    private TblIndicatorMapper tblIndicatorMapper;
    @Resource
    private TblIndicatorMySqlMapper tblIndicatorMySqlMapper;

    @Override
    public Map<String, Object> findIndicatorByUseridAndSlouid(PageInfo<TblIndicator> pageInfo, BigDecimal staffid) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<>(0);
            pageInfo.setTlist(this.tblIndicatorMapper.findIndicatorByUseridAndSlouid(pageInfo, staffid));
            pageInfo.setTotalRecord(this.tblIndicatorMapper.findIndicatorByUseridAndSlouidCount(staffid));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", pageInfo);
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(this.tblIndicatorMySqlMapper.findIndicatorByUseridAndSlouid(pageInfo, staffid));
            pageInfo.setTotalRecord(this.tblIndicatorMySqlMapper.findIndicatorByUseridAndSlouidCount(staffid));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", pageInfo);
            return resultMap;
        }
    }

    @Override
    public Map<String, Object> findIndicatorByJKZX(String solutionid, PageInfo<TblIndicator> pageInfo) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(this.tblIndicatorMapper.findIndicatorByJKZX(solutionid, pageInfo));
            pageInfo.setTotalRecord(this.tblIndicatorMapper.findIndicatorByJKZXCount(solutionid));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", pageInfo);
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(this.tblIndicatorMySqlMapper.findIndicatorByJKZX(solutionid, pageInfo));
            pageInfo.setTotalRecord(this.tblIndicatorMySqlMapper.findIndicatorByJKZXCount(solutionid));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", pageInfo);
            return resultMap;
        }
    }

    @Override
    public TblIndicator findOne(String indicatorid) {
        return tblIndicatorMapper.findIndicatorid(indicatorid);
    }

    @Override
    public TblIndicatorMySql findMySqlOne(String indicatorid) {
        return tblIndicatorMySqlMapper.findIndicatorid(indicatorid);
    }
}
